
var FormData = require( 'form-data' );
var fs = require( 'fs' );
const fetch = require( 'node-fetch' )
module.exports = class extends think.global.service {
  async indexAction () {
    var postData = this.post()
    var formData = new FormData()
    for ( var i in postData ) {
      formData.append( i, postData[i] )
    }
    formData.append( 'voice', fs.createReadStream( this.file( 'voice' ).path ) )
    formData.append( 'client', 'news' )

    try {
      var result
      await fetch( this.$url, { method: 'POST', body: formData } ).then( function( res ) {
        return res.json()
      } ).then( function( json ) {
        result = json
      } );
      this.json( result )
    } catch ( e ) {
      this.ctx.fail( 1000, e.message )
    }
  }
};
// {
//   "appid":"wx283f05dbb353b933",
//   "openid":"oo5pZ0-cIg9kiDc3H0HCV9ShrXAo",
//   "voice":1,
//   "cs_id":100,
//   "send_type":1002,
//   "send_time":1539225384,
//   "type":"text"
// }